package com.ruoyi.framework.handlers;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ruoyi.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;


import java.time.LocalDateTime;

public class MPMetaObjectHandler  implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println(SecurityUtils.getUserId());
        this.strictInsertFill(metaObject, "create_time", () -> LocalDateTime.now(), LocalDateTime.class);
        this.strictInsertFill(metaObject, "create_by", () -> String.valueOf(SecurityUtils.getUserId()), String.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "update_time", () -> LocalDateTime.now(), LocalDateTime.class);
        this.strictUpdateFill(metaObject, "update_by", () -> String.valueOf(SecurityUtils.getUserId()), String.class);
    }
}
